// 时间格式化
function formatTime(timestamp, format) {  
  const date = new Date(timestamp);  
  const year = date.getFullYear();  
  const month = String(date.getMonth() + 1).padStart(2, '0');  
  const day = String(date.getDate()).padStart(2, '0');  
  const hours = String(date.getHours()).padStart(2, '0');  
  const minutes = String(date.getMinutes()).padStart(2, '0');  
  const seconds = String(date.getSeconds()).padStart(2, '0');
  return format  
   .replace('YYYY', year)  
   .replace('MM', month)  
   .replace('DD', day)  
   .replace('HH', hours)  
   .replace('mm', minutes)  
   .replace('ss', seconds);  
 };
//  两个时间段的间隔
 function differenceInHours(date1, date2) {  
   let format_date1 = dateToTimestamp(date1)
   let format_date2 = dateToTimestamp(date2)
  const diffInMilliseconds = Math.abs(format_date1 - format_date2);  
  const diffInSeconds = Math.round(diffInMilliseconds / 1000);  
  const diffInMinutes = Math.round(diffInSeconds / 60);  
  const diffInHours = diffInMinutes / 60;  
  // const diffInHours = Math.round(diffInMinutes / 60);  
  // return diffInHours;  
  // 保留两位小数  
 return parseFloat(diffInHours.toFixed(2));  
 }
 //日期转时间戳
 function dateToTimestamp(date) {  
   let formatDate = new Date(date)
  return formatDate.getTime();  
 }
 export {formatTime,differenceInHours,dateToTimestamp}